package com.maibow.controller.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.maibow.controller.base.BaseController;
import com.maibow.entity.site.Area;
import com.maibow.entity.site.City;
import com.maibow.entity.site.Province;
import com.maibow.exception.BusinessException;
import com.maibow.exception.ErrorConstants;
import com.maibow.service.admin.SiteService;
import com.maibow.util.PageData;

/**
 * 
 * 脉博网络后台管理系统
 * 包名：com.maibow.controller.organ
 * 文件名：OrganController.java
 * 作者: 吴比(Wubi)
 * 时间：2015年4月7日-上午9:10:04
 * Copyright@ 2015湖南脉博网络科技有限公司-版权所有
 *
 */
@Controller
@RequestMapping(value = "/site")
public class SiteController extends BaseController {
    @Resource(name = "siteService")
    private SiteService siteService;

    /**
     * 
     * queryAllAreaListByCityCode(这里用一句话描述这个方法的作用)
     * (这里描述这个方法适用条件 – 可选)
     * 标记：@param citycode
     * 标记：@param request
     * 标记：@param response
     * 标记：@return
     * 标记：@throws Exception
     * 返回值：ModelAndView
     * 作者：吴比(Wubi)
     * 
     * @exception
     * @since 1.0.0
     */
    @ResponseBody
    @RequestMapping("/queryAllAreaListByCityCode/{citycode}")
    public ModelAndView queryAllAreaListByCityCode(@PathVariable String citycode, HttpServletRequest request, HttpServletResponse response) throws Exception {
        logger.debug("queryAllAreaListByCityCode begin=================================");
        PageData pageData = this.getPageData();
        pageData.put("citycode", citycode);
        List<Area> areaList = null;
        try {
            areaList = siteService.queryAllAreaListByCityCode(pageData);
        } catch (BusinessException e) {
            // TODO Auto-generated catch block
            throw new BusinessException(ErrorConstants.BASE_ERROR.CODE, ErrorConstants.BASE_ERROR.DES);
        }
        ModelAndView modelView = new ModelAndView();
        Map<String, Object> modelMap = new HashMap<String, Object>();
        modelMap.put("areaList", areaList);
        modelView.addAllObjects(modelMap);
        logger.debug("queryAllAreaListByCityCode end=================================");
        return modelView;
    }

    /**
     * 
     * queryAllCityListByProvinceCode(
     * 这里用一句话描述这个方法的作用)
     * (这里描述这个方法适用条件 – 可选)
     * 标记：@param provincecode
     * 标记：@param request
     * 标记：@param response
     * 标记：@return
     * 标记：@throws Exception
     * 返回值：ModelAndView
     * 作者：吴比(Wubi)
     * 
     * @exception
     * @since 1.0.0
     */
    @ResponseBody
    @RequestMapping("/queryAllCityListByProvinceCode/{provincecode}")
    public ModelAndView queryAllCityListByProvinceCode(@PathVariable String provincecode, HttpServletRequest request, HttpServletResponse response) throws Exception {
        logger.debug("queryAllCityListByProvinceCode begin=================================");
        PageData pageData = this.getPageData();
        pageData.put("provincecode", provincecode);
        List<City> cityList = null;
        try {
            cityList = siteService.queryAllCityListByProvinceCode(pageData);
        } catch (BusinessException e) {
            // TODO Auto-generated catch block
            throw new BusinessException(ErrorConstants.BASE_ERROR.CODE, ErrorConstants.BASE_ERROR.DES);
        }
        ModelAndView modelView = new ModelAndView();
        Map<String, Object> modelMap = new HashMap<String, Object>();
        modelMap.put("cityList", cityList);
        modelView.addAllObjects(modelMap);
        logger.debug("queryAllCityListByProvinceCode end=================================");
        return modelView;
    }

    /**
     * 
     * queryAllProvinceList(这里用一句话描述这个方法的作用)
     * (这里描述这个方法适用条件 – 可选)
     * 标记：@param request
     * 标记：@param response
     * 标记：@return
     * 标记：@throws Exception
     * 返回值：ModelAndView
     * 作者：吴比(Wubi)
     * 
     * @exception
     * @since 1.0.0
     */
    @ResponseBody
    @RequestMapping("/queryAllProvinceList")
    public ModelAndView queryAllProvinceList(HttpServletRequest request, HttpServletResponse response) throws Exception {
        logger.debug("queryAllProvinceList begin=================================");
        PageData pageData = this.getPageData();
        List<Province> provinceList = null;
        try {
            provinceList = siteService.queryAllProvinceList(pageData);
        } catch (BusinessException e) {
            // TODO Auto-generated catch block
            throw new BusinessException(ErrorConstants.BASE_ERROR.CODE, ErrorConstants.BASE_ERROR.DES);
        }
        ModelAndView modelView = new ModelAndView();
        Map<String, Object> modelMap = new HashMap<String, Object>();
        modelMap.put("provinceList", provinceList);
        modelView.addAllObjects(modelMap);
        logger.debug("queryAllProvinceList end=================================");
        return modelView;
    }
}